package com.qf.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.dao.EvaluateMapper;
import com.qf.entitys.Evaluate;
import com.qf.service.EvaluateService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class EvaluateServiceImpl implements EvaluateService {

    @Resource
    private EvaluateMapper mapper;

    @Override
    public int deleteByPrimaryKey(Integer evaluateId) {
        return mapper.deleteByPrimaryKey(evaluateId);
    }

    @Override
    public int insert(Evaluate record) {
        return 0;
    }

    @Override
    public int insertSelective(Evaluate record) {
        return mapper.insertSelective(record);
    }

    @Override
    public Evaluate selectByPrimaryKey(Integer evaluateId) {
        return mapper.selectByPrimaryKey(evaluateId);
    }

    @Override
    public int updateByPrimaryKeySelective(Evaluate record) {
        return mapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Evaluate record) {
        return 0;
    }

    @Override
    public PageInfo<Evaluate> selectList(Evaluate evaluate, Integer pageindex) {
        PageHelper.startPage(pageindex,10);
        List<Evaluate> list = mapper.selectList(evaluate);
        for (Evaluate e :list){
            System.out.println(e);
        }
        PageInfo<Evaluate> evaluatePageInfo = new PageInfo<>(list);
        return evaluatePageInfo;
    }

    @Override
    public int deleteByIds(Integer[] ids) {
        if (ids.length<=0) {
            return 0;
        }
        for (Integer id : ids) {

            int i = deleteByPrimaryKey(id);
            if (i==0){
                //出现错误就向上抛异常，事务默认遇到运行时异常就会回滚操作
                throw new RuntimeException("删除失败");
            }
        }
        //如果没问题就返回1
        return 1;
    }
}
